var failedCount = 0;
$(document).ready(function(){   
	monitor();
})  

function monitor() {
	var params = new Object();
	params["rand"] = Math.random();
	$.ajax({url:"../system/TodoEvent/monitor", data:params, type:'post', dataType:'xml', timeout:5000, error:onError, success:onSuccess}); 
}


function onError() {
	if(failedCount==4)
		$('#content').html("Connect to server failed, reconnect automatically, if this problem still exist, login again ");
	failedCount ++;
	setTimeout("monitor()", "10000");
}

function onSuccess(xml) {
	var response = $(xml).find('response').attr('result');
	if(response=='true') {
		var count = $(xml).find('content').attr('count');
		var expire = $(xml).find('content').attr('expire');
		$('#content').html("You have <font style=\"color:red;font-weight:bold;font-size:20px\">"+count+"</font> tasks to do and <font style=\"color:red;font-weight:bold;font-size:20px\">"+expire+"</font> tasks expired");
		setTimeout("monitor()", "10000");
		$('#cut').css("display", "none");
	}
	else {
		$('#content').html("You are already time out, login again please! ");
	}
	failedCount = 0;
}